<?php

// ------------------------------------------------------------------------
// |@Author       : Jarmin <edshop@qq.com>
// |@----------------------------------------------------------------------
// |@Date         : 2025-05-07 01:08:27
// |@----------------------------------------------------------------------
// |@LastEditTime : 2025-05-11 01:44:07
// |@----------------------------------------------------------------------
// |@LastEditors  : Jarmin <topextend@qq.com>
// |@----------------------------------------------------------------------
// |@Description  :
// |@----------------------------------------------------------------------
// |@FilePath     : SystemApiInterfaces.php
// |@----------------------------------------------------------------------
// |@Copyright (c) 2025 http://www.ladmin.cn All Rights Reserved.
// ------------------------------------------------------------------------
declare (strict_types=1);

namespace think\admin\model;

use think\admin\Model;

/**
 * 系统接口模型
 * Class SystemApiInterfaces
 * @package think\admin\model
 */
class SystemApiInterfaces extends Model
{
    // 设置字段信息
    protected $schema = [
        'id'              => 'int',
        'path'            => 'string',
        'method'          => 'string',
        'current_version' => 'string',
        'min_version'     => 'string',
        'max_version'     => 'string',
        'status'          => 'int',
        'description'     => 'string',
        'created_at'      => 'datetime',
        'updated_at'      => 'datetime',
    ];

    // 获取器
    public function getStatusTextAttr($value, $data)
    {
        $status = [0 => '禁用', 1 => '启用'];
        return $status[$data['status']] ?? '未知';
    }

    public function getMethodTextAttr($value, $data)
    {
        $methods = [
            'GET'     => 'GET',
            'POST'    => 'POST',
            'PUT'     => 'PUT',
            'DELETE'  => 'DELETE',
            'PATCH'   => 'PATCH',
            'OPTIONS' => 'OPTIONS'
        ];
        return $methods[$data['method']] ?? '未知';
    }

    // 修改器
    public function setPathAttr($value)
    {
        return trim($value, '/');
    }

    public function setMethodAttr($value)
    {
        return strtoupper($value);
    }

    public function setCurrentVersionAttr($value)
    {
        return strtolower($value);
    }

    public function setMinVersionAttr($value)
    {
        return strtolower($value);
    }

    public function setMaxVersionAttr($value)
    {
        return strtolower($value);
    }
}
